package cn.diancan.util;


import java.util.regex.Matcher;
import java.util.regex.Pattern;

import cn.diancan.model.types.NiceCodeType;

/**
 * 验证工具
 * @author Sky
 *
 */
public class RegexVerifyUtil {
    	
    	//中文 英文数字 - _
  	/*public static boolean ischeckUserName(String str){
  	    	if(str.length()<2 && str.length()>16){
  	    	    return false;
  	    	}
  		char [] c= str.toCharArray();
  		for (int i = 0; i < c.length; i++) {  
  			Pattern p = Pattern.compile("[\u4e00-\u9fa5|0-9|a-z|A-Z|_]");
  			Matcher m = p.matcher(""+c[i]); 
  			if(m.find()){
  			    continue;
  			}
  			return false;
  		}
  		return true; 
  	}*/
    	
     public static void main(String[] args) {
	 /*System.out.println(getRealMaxId("123456",true));
	 System.out.println(getUNNiceNumber("88888", 2));*/
	 /*boolean r=isIOS("Mozilla/5.0  AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A403 Safari/8536.25");
	 System.out.println(r);*/
	 
	 System.out.println(isTimeScope("00:12-11:61"));
	 
    	   /* String sh="http://play.vlook.cn:8080/down/servlet/VideoPlay?vid=aX.mp4";
    	    String s="http://play\\.vlook\\.cn:8080/down/servlet/VideoPlay\\?vid=(.+)\\.mp4";
    	   String s2="http://play\\.vlook\\.cn:8080/down/servlet/VideoPlay\\?vid=(\\.+)";
    	    
    	    
    	    System.out.println(sh.replaceAll(s, s2)); 
    	    System.out.println(Pattern.compile(s).
    		    matcher(sh).matches());*/
	/* String s ="123456";
 	  Matcher m = Pattern.compile("\\d*(111|222|333|444|555|666|777|888|999|000|4321|5432|6543|7654|8765|9876|1234|2345|3456|4567|5678|6789)\\d*").matcher(s);
 	  
 	  System.out.println(m.matches()); 
 	  
 	  String ns=m.group(1);
 	  System.out.println(m.group(1));
 	  String ns2=String.valueOf(Integer.valueOf(ns)+1);
 	  System.out.println(s.replaceAll(ns, ns2));;
 	  
 	  System.out.println(s.substring( m.start(),m.end()));*/
	  
	  
     }
    	public static boolean ischeckUserName(String str){
    	    	if(Pattern.compile("[\u4e00-\u9fa50-9a-zA-Z_]{2,16}").matcher(str).matches()){
	  	    return true;
	  	}
		return false; 
	}
    	
  	
  	public static boolean isWeiXinNum(String str){ 
  	  	if(Pattern.compile("[0-9a-zA-Z|_]{2,16}").matcher(str).matches()){
  	  	    return true;
  	  	}
  		return false; 
  	}
  	
  	//腾讯QQ号从10000开始
  	public static boolean isQqNum(String str){ 
	  	if(Pattern.compile("[0-9]{5,12}").matcher(str).matches()){
	  	    return true;
	  	}
		return false; 
	}
  	
  	public static boolean isPhoneNum(String str){ 
	  	if(Pattern.compile("^1[34578][0-9]{9}$").matcher(str).matches()){
	  	    return true;
	  	}
		return false; 
	}
  	
  	public static boolean isRealName(String str){
  	    	if(Pattern.compile("^[\u4e00-\u9fa50]{2,6}$").matcher(str).matches()){
	  	    return true;
	  	}
		return false; 
  	}
      	
        public static boolean isTimeScope(String str) { 
        	if (Pattern.compile("^([0-1]\\d|2[0-4]):([0-5]\\d)-([0-1]\\d|2[0-4]):([0-5]\\d)$").matcher(str).matches()) {
        	    return true;
        	}
        	return false;
        }
        
  	
  	/*public static boolean isLianghao(String str){
  	      
  	      if(Pattern.compile("(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){5}\\d").matcher(str).matches()){
  		  return true;
  	      }
  	      return false;
  	}
  	
  	public static boolean isLig(String str){ 
  	  if(Pattern.compile("(?<=\\d|^)(?:(?:9(?=8|\\d))?(?:8(?=7|\\d))?(?:7(?=6|\\d))?(?:6(?=5|\\d))?(?:5(?=4|\\d))?(?:4(?=3|\\d))?(?:3(?=2|\\d))?(?:2(?=1|\\d))?(?:1(?=0|\\d))?(?:0(?=\\d|$))?)(?=\\d|$)").matcher(str).matches()){
		  return true;
	      }
	      return false;
  	}*/
  	
  	
  	public static boolean isLianghao(String str){ 
  	      if(Pattern.compile("\\d*(111|222|333|444|555|666|777|888|999|000|4321|5432|6543|7654|8765|9876|1234|2345|3456|4567|5678|6789)\\d*").matcher(str).matches()){
		  return true;
	      } 
	      return false;
	}
  	
  	 
  	
  	public static String getRealMaxId(String maxId,boolean addOne){
          	  String str = addOne?String.valueOf(Long.valueOf(maxId)+1):maxId;
          	  Matcher m = Pattern.compile("\\d*(111|222|333|444|555|666|777|888|999|000|4321|5432|6543|7654|8765|9876|1234|2345|3456|4567|5678|6789)\\d*").matcher(str);
          	//Matcher m = Pattern.compile("\\d*(11111|22222|33333|44444|55555|66666|77777|88888|99999|00000)\\d*").matcher(str);
          	  if(!m.matches()){
          	      return str;
          	  }
          	  if(0<m.groupCount()){
          	      String ns=m.group(1); 
          	      int i = str.indexOf(ns)+ns.length();
          	      int j = ((str.length()-i)*10);
          	      j=j==0?1:j;
          	      String newStr = String.valueOf(Long.valueOf(str)+j);
          	      if(i>0){
          		  newStr=String.valueOf(Long.valueOf(newStr)/j*j);
          	      }
          	      return getRealMaxId(newStr,false); 
          	  }
          	  return str;
  	}
  	
  	 
  	
  	
    public static String getUNNiceNumber(String nowId, NiceCodeType niceType)throws Exception {
	String str = nowId;
	Matcher m = null;
	if(niceType.equals(NiceCodeType.GeneralNice)){
	    m = Pattern.compile("\\d*(111|222|333|444|555|666|777|888|999|000|4321|5432|6543|7654|8765|9876|1234|2345|3456|4567|5678|6789)\\d*").matcher(str);
	}else if(niceType.equals(NiceCodeType.VeryNice)){
	    m = Pattern.compile("(11111|22222|33333|44444|55555|66666|77777|88888|99999|111111|222222|333333|444444|555555|666666|777777|888888|999999|1111111|2222222|3333333|4444444|5555555|6666666|7777777|8888888|9999999|11111111|22222222|33333333|44444444|55555555|66666666|77777777|88888888|99999999)").matcher(str);
	}else if(niceType.equals(NiceCodeType.NotReservedNice)){
	    return str;
	} else{
	    throw new Exception();//绝对保留
	}
	// 
	if (!m.matches()) {
	    return str;
	}
	if (0 < m.groupCount()) {
	    String ns = m.group(1);
	    int i = str.indexOf(ns) + ns.length();
	    int j = ((str.length() - i) * 10);
	    j = j == 0 ? 1 : j;
	    String newStr = String.valueOf(Long.valueOf(str) + j);
	    if (i > 0) {
		newStr = String.valueOf(Long.valueOf(newStr) / j * j);
	    }
	    return getUNNiceNumber(newStr, niceType);
	}
	return str;
    }
    public static String getAllNumber(String s){ 
        Pattern p = Pattern.compile("[0-9]");
        Matcher m = p.matcher(s);
        String number ="";
        while (m.find()) {
    	number+= m.group();
        }
        return number;
    }
    /**
     * 是否是ios系统
     * @param userAgent
     * @return
     */
    public static boolean isIOS(String userAgent){ 
	if(Pattern.compile(".*(iPhone|iPod|Android|ios).*").matcher(userAgent).matches()){
	    return true;
	}
	return false;
    }
    
    public static String s(){
	
	return null;
    }
  	
    /*if(ns.equals("999")){
	  int i = str.indexOf("999")+3;
	  int j=((str.length()-i)*10);
	  return getRealMaxId(String.valueOf(Long.valueOf(str)+(j==0?1:j)),false);
	  //System.out.println(i); 
      }else{
      	String ns2=String.valueOf(Integer.valueOf(ns)+1);
	if(ns.equals("000")){
		   ns2="001";
	      	}
	return getRealMaxId(str.replaceAll(ns, ns2),false);
      } */
  	
  	
  	
  	 
  	 
  	 
  	 
  	 
}
